var MyTable={
    searchForm:"searchForm",
    searchUrl:"/online/list",
	tableId:"lgTable",
	table:null,
	prefix:"/online/"
};

$(function() {
    var defaultColunms = MyTable.initColumn();
    var table = new BSTable(MyTable.tableId, MyTable.searchUrl,defaultColunms);
	table.setQueryParams(getFormJson(MyTable.searchForm));
	table.setSortName("asc");
	table.setSortOrder("gmt_create");
	MyTable.table = table.init(0);
	//loadTreeData();
});
function reLoad() {
	MyTable.table.refresh(getFormJson(MyTable.searchForm));
}
function resetSearch(){
	cleanFormVal(MyTable.searchForm);
	MyTable.table.refresh(null);
}

MyTable.initColumn = function () {
    var columns =  [
		{field : 'engine', title : 'engine'},
		{field : 'tableName',title : '表名称'},
		{field : 'tableNote',title : '表注释'},
		{field : 'tableNote',title : '表注释'},
		{field : 'gmtCreate',title : '创建时间'},
		{field : 'position',title : '生成包名'},
		{field : 'prefix',title : '去除前缀'},
		{
			title : '操作',
			field : 'id',
			align : 'center',
			formatter : function(value, row, index) {
				var e = '<a  class="btn btn-primary btn-sm ' + editBtn + '" href="#" mce_href="#" title="编辑" onclick="edit(\''
				+ row.id
				+ '\')"><i class="fa fa-edit "></i></a> ';
			var o = "<a class='btn btn-warning btn-sm "+autoBtn+"' href='#' title='在线生成'  onclick='autoDo("+JSON.stringify(row) +")'><i class='fa fa-cloud-download'></i></a>";
			
			var d = '<a  class="btn btn-danger btn-sm ' + delBtn + '" href="#" mce_href="#" title="删除" onclick="delRow(\''
			+ row.id
			+ '\')"><i class="fa fa-remove "></i></a> ';
			return  d+e + o ;
			}
		} ];
    return columns;
};


function edit(id) {
	layer.open({
		type : 2,
		title : '修改表结构',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '520px' ],
		content : MyTable.prefix+'/edit/'+id
	});
}


function autoDo(row){
	if(!row.position){
		layer.msg("包名不能为空!");
		return;
	}
	layer.msg("请稍后..");
	var down=layer.open({
		type : 2,
		title : '下载包',
		maxmin : true,
		shadeClose : false, // 点击遮罩关闭层
		area : [ '800px', '670px' ],
		content : MyTable.prefix+"down?id="+row.id
	});
	layer.close(down);
}


function delRow(id){
    var config={
			url : MyTable.prefix+"/deleteRow",
			data:{"id":id},
			sureDo:true,
			msg:"确定删除记录？"
	}
	EasyAjax.post_json(config,function(r){
		layer.msg(r.msg);
		if (r.code == 0){
			reLoad();
		} 
	});
}


